package com.example.xjtuse_pc.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.xjtuse_pc.mobilesafe.R;

/**
 * Created by XJTUSE-PC on 2016/3/17.
 */
public class SettingItemView extends RelativeLayout {
    private String desc_on,desc_off;
    private CheckBox cb_status;
    private TextView tv_desc;
    private TextView tv_title;
    public SettingItemView(Context context) {
        super(context);
        iniView(context);
    }

    public SettingItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        iniView(context);
        String  title=attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","title");
        desc_on=attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","desc_on");
        desc_off=attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","desc_off");
        tv_title.setText(title);
        setDesc(desc_off);

    }

    public SettingItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        iniView(context);
    }

    private void iniView(Context context) {
        View.inflate(context, R.layout.setting_item_view,SettingItemView.this);
        cb_status = (CheckBox) this.findViewById(R.id.cb_status);
        tv_desc = (TextView) this.findViewById(R.id.tv_desc);
        tv_title = (TextView) this.findViewById(R.id.tv_title);



    }
    /**
     * 校验组合控件是否选中
     */
    public boolean isChecked(){
     return cb_status.isChecked();
    }
    /**
     * 设置组合控件状态
     */
    public void setChecked(boolean isChecked){
        if(isChecked){
            setDesc(desc_on);
        }else
            setDesc(desc_off);
        cb_status.setChecked(isChecked);
    }
    /**
     * 设置状态显示
     */
    public void  setDesc(String s){
        tv_desc.setText(s);
    }
}
